//
//  HomeDataModel.swift
//  EasyDana
//
//  Created by mac on 2024/10/10.
//

import Foundation



struct HomeDataModel: Codable {
    struct HomeDataHastingModel: Codable {
        let punch: String //客服小手机logo
        let theatre: String //客服页面H5链接
        let ceria: String //feedback
    }
    
    struct CMentsModel: Codable {
        let convoys: String
        let jno: String
    }
    
    enum TillyModel: Codable {
        enum CodingKeys: CodingKey {
            case cordially
        }
        case banner(BannerTillyModel)
        case loan(LoanTillyModel)
        case order(OrderTillyModel)
        init(from decoder: any Decoder) throws {
            let container = try decoder.container(keyedBy: HomeDataModel.TillyModel.CodingKeys.self)
            let cordially = try container.decode(String.self, forKey: .cordially)
            switch cordially {
            case "death":
                let banner = try BannerTillyModel(from: decoder)
                self = .banner(banner)
                break
            case "fond", "yet":
                let loan = try LoanTillyModel(from: decoder)
                self = .loan(loan)
                break
            default:
                let order = try OrderTillyModel(from: decoder)
                self = .order(order)
                break
            }
        }
        
        func encode(to encoder: any Encoder) throws {
            
        }
    }
    
    struct BannerTillyModel: Codable {
        struct BannerModel: Codable {
            let drank: String
            let factor: String
        }
        let cordially: String
        let stuffs: [BannerModel]
    }
    
    struct LoanTillyModel: Codable {
        struct StuffModel: Codable {
            let genteel: Int//产品id
            let elegant: String//产品名称
            let coffree: String//产品logo
            let evenings: String//申请按钮的文字
            let painted: String//产品额度
            let proves: String//产品名下面的描述文字
            let terrible: String//产品期限
            let wed: String//产品期限标题
            let cost: String//产品利率
            let sent: String//产品利率标题
        }
        let cordially: String
        let stuffs: [LoanTillyModel.StuffModel]
    }
    
    struct OrderTillyModel: Codable {
        struct StuffModel: Codable {
            let genteel: Int//产品id
            let elegant: String//产品名称
            let coffree: String//产品logo
            let evenings: String//申请按钮的文字
            let painted: String//产品额度
            let proves: String//产品名下面的描述文字
            let terrible: String//产品期限
            let wed: String//产品期限标题
            let cost: String//产品利率
            let sent: String//产品利率标题
        }
        let cordially: String
        let stuffs: [OrderTillyModel.StuffModel]
    }
    
    let hastings: HomeDataHastingModel
    let minuet: [String]//跑马灯
    let clements: CMentsModel
    let swords: Int //是否展示还款提醒
    let duel: String //还款提醒弹框
    let tilly: [TillyModel]
    
    init(from decoder: any Decoder) throws {
        let container: KeyedDecodingContainer<HomeDataModel.CodingKeys> = try decoder.container(keyedBy: HomeDataModel.CodingKeys.self)
        self.hastings = try container.decode(HomeDataHastingModel.self, forKey: .hastings)
        self.minuet = try container.decode([String].self, forKey: .minuet)
        self.clements = try container.decode(CMentsModel.self, forKey: .clements)
        self.swords = try container.decode(Int.self, forKey: .swords)
        self.duel = try container.decode(String.self, forKey: .duel)
        self.tilly = try container.decode([TillyModel].self, forKey: .tilly)
    }
    
    
}
